package com.example.viewmodel_probe;

import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.lifecycle.ViewModel;

class MyViewModel extends ViewModel {
    public int number;
}

public class MainActivity extends AppCompatActivity {

    MyViewModel myViewModel = new MyViewModel();

    TextView tv;

    Button btn1, btn2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

//        myViewModel = ViewModelProvider.
//                .of(this).get(MyViewModel.class);
        tv = findViewById(R.id.tv);
        btn1 = findViewById(R.id.button);
        btn2 = findViewById(R.id.button2);

        btn1.setOnClickListener(v -> {
            myViewModel.number++;
            tv.setText(String.valueOf(myViewModel.number));
        });
        btn2.setOnClickListener(v -> {
            myViewModel.number += 2;
            tv.setText(String.valueOf(myViewModel.number));
        });

    }


}